package statistics;

import engine.Creature;
import engine.World;

import java.io.FileWriter;
import java.io.IOException;

/**
 * Created by kbarzilo on 12.09.2014.
 */
public class WriteStatistics {
    public static void writeToFile(World world){
        try {
            FileWriter fileWriter = new FileWriter("full_statistics.csv", true);
            for (Creature currCreature : world.creaturesOfWorld) {
                StringBuilder str = new StringBuilder();
                str.append(world.getYearNumber()).append(",");
                str.append(world.getDayNumber()).append(",");
                str.append(currCreature.number).append(",");
                str.append(currCreature.position.getXPosition()).append(",");
                str.append(currCreature.position.getYPosition()).append(",");
                str.append(currCreature.getAge()).append(",");
                str.append(currCreature.getHealth()).append(",");
                str.append(currCreature.getHunger()).append(",");
                str.append(currCreature.getEnergy()).append(",");
                str.append(currCreature.getTestosterone()).append(",");
                str.append(currCreature.decision).append(",");
                str.append(currCreature.getWidth()).append(",");
                str.append(currCreature.getSpeed()).append(",");
                str.append(currCreature.getStamina()).append(",");
                str.append(currCreature.getFoodNeed()).append(",");
                str.append(currCreature.getMeatPrefer()).append(",");
                str.append(currCreature.getMaxEnergy()).append(",");
                str.append(currCreature.getEnergyRecovery()).append(",");
                str.append(currCreature.getVision()).append(",");
                str.append(currCreature.getAttack()).append(",");
                str.append(currCreature.getArmor()).append(",");
                str.append(currCreature.getFather()).append(",");
                str.append(currCreature.getMother()).append(",");
                str.append(currCreature.getSex()).append(",");
                str.append(currCreature.getGenWidth()).append(",");
                str.append(currCreature.getGenSpeed()).append(",");
                str.append(currCreature.getGenStamina()).append(",");
                str.append(currCreature.getGenFoodNeed()).append(",");
                str.append(currCreature.getColor().getRed()).append(",");
                str.append(currCreature.getColor().getGreen()).append(",");
                str.append(currCreature.getColor().getBlue()).append("\n");
                System.out.println(str);
                fileWriter.write(str.toString());
            }
            fileWriter.flush();
            fileWriter.close();
        } catch (IOException ex){
            ex.printStackTrace();
        }
    }
}
